import { Controller, Inject, Get, Query } from '@midwayjs/core'
import { RescueRecordService } from '../../service/admin/RescueRecordService'
import { BaseController } from '../base.chontroller'

@Controller('/rescue_record')
export class RescueRecordController extends BaseController {
  @Inject()
  service!: RescueRecordService

  @Get('/list')
  async list(
    @Query('page') page?: string,
    @Query('pageSize') pageSize?: string
  ) {
    try {
      const pageNum = page ? parseInt(page) : 1
      const pageSizeNum = pageSize ? parseInt(pageSize) : 10
      const data = await this.service.list(pageNum, pageSizeNum)
      return this.success<IList<any>>(data)
    } catch (err: any) {
      return this.fail(err.message || '获取列表失败')
    }
  }

  @Get('/detail')
  async detail(@Query('id') id?: string) {
    if (!id) {
      return this.fail('缺少ID参数')
    }
    try {
      const data = await this.service.getById(parseInt(id))
      if (!data) {
        return this.fail('救助记录不存在')
      }
      return this.success(data)
    } catch (err: any) {
      return this.fail(err.message || '获取详情失败')
    }
  }
}
